package com.example.rabbitmq7.config;

import com.example.rabbitmq7.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DLConfig {
    @Bean("normalExchange")
    public Exchange normalExchange() {
        return ExchangeBuilder.directExchange(Constants.NORMAL_EXCHANGE).build();
    }

    @Bean("normalQueue")
    public Queue normalQueue() {
        return QueueBuilder.durable(Constants.NORMAL_QUEUE)
                .ttl(10000)
                .deadLetterExchange(Constants.DL_EXCHANGE)
                .deadLetterRoutingKey("dl")
                .build();
    }

    @Bean("normalBinding")
    public Binding normalBinding(@Qualifier("normalExchange") Exchange exchange, @Qualifier("normalQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("normal").noargs();
    }

    @Bean("normalQueue2")
    public Queue normalQueue2() {
        return QueueBuilder.durable(Constants.NORMAL_QUEUE2)
                .deadLetterExchange(Constants.DL_EXCHANGE)
                .deadLetterRoutingKey("dl")
                .build();
    }

    @Bean("normalBinding2")
    public Binding normalBinding2(@Qualifier("normalExchange") Exchange exchange,@Qualifier("normalQueue2") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("normal2").noargs();
    }

    @Bean("DLExchange")
    public Exchange DLExchange() {
        return ExchangeBuilder.directExchange(Constants.DL_EXCHANGE).build();
    }

    @Bean("DLQueue")
    public Queue DLQueue() {
        return QueueBuilder.durable(Constants.DL_QUEUE).build();
    }

    @Bean("DLBinding")
    public Binding DLBinding(@Qualifier("DLExchange") Exchange exchange,@Qualifier("DLQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("dl").noargs();
    }
}
